<template>
  <div class="app-container" style="padding: 0 !important;">
    <el-form inline size="small" ref="queryForm" :model="queryParams" v-show="showSearch" label-width="100px">
      <el-form-item label="关键字" prop="keyWord">
        <el-input style="width:350px;" v-model="queryParams.keyWord" placeholder="请输入订单编号、承租人信息、车牌号、车型信息"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="订单编号" align="center" >
        <template slot-scope="{ row }">
          <span >{{ row.orderNo }}</span>
        </template>
      </el-table-column>
      <el-table-column label="承租人" align="center"  show-overflow-tooltip>
        <template slot-scope="{ row }">
          <div>
            {{ row.memberName }}
            <div>{{ row.memberPhone }}</div>
            <span v-if="row.memberType==1">{{row.enterpriseName}}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="车牌号" align="center" show-overflow-tooltip>
        <template slot-scope="{ row }">
          <div>{{ row.carNo || '/' }}</div>
        </template>
      </el-table-column>

      <el-table-column label="预定车型" align="center" prop="modelName" show-overflow-tooltip>
        <template slot-scope="{ row }">
          <div>{{ row.modelName }}</div>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center"  show-overflow-tooltip  prop="orderStatus">
        <template slot-scope="{ row }">
          <dict-tag style="display: inline-block" :options="dict.type.sys_order_status" :value="row.orderStatus" />
        </template>
      </el-table-column>
      <el-table-column label="下单时间"  align="center" min-width="130" show-overflow-tooltip prop="createTime" />


      <el-table-column label="操作" width="160"  fixed="left"  align="center">
        <template slot-scope="{row}" >
          <el-button type="text" size="mini" v-if="type === 5" @click="handleCommand('handleJiaocheyanche',row)">交车验车</el-button>
          <el-button type="text" size="mini" v-if="type === 6" @click="handleCommand('orderRenewal',row)">订单续租</el-button>
          <el-button type="text" size="mini" v-if="type === 7" @click="handleCommand('earlyReturn',row)">提前还车</el-button>
          <el-button type="text" size="mini" v-if="type === 8" @click="handleCommand('changeCar',row)">订单换车</el-button>
          <el-button type="text" size="mini" v-if="type === 9" @click="handleCommand('handleHuancheyanche',row)">还车验车</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :pageSizes="[5,10,15,20,50]" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />


  </div>
</template>

<script>
import * as api from "@/api/order";

export default {
  dicts: ['memberType', 'sys_order_source', 'sys_order_status', 'rental_type'],
  props: {
    type: {
      type: Number,
      default: 0,
    }
  },
  data() {
    return {
      loading: false,
      list: [],
      // 总条数
      total: 0,
      // 显示搜索条件
      showSearch: true,
      queryParams: {
        keyWord: "",//车牌号
        type: this.type>6?6:this.type,//车型id
        pageNum: 0,//页码   必选
        pageSize: 5,//每页显示数据 必选
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true
      api.index(this.queryParams).then((response) => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCommand(command, row) {
      this.$emit("handleCommand",command, row)
    },
    carStatusFmt(row) {
      if (row.lineStatus == 0) {
        return '已下线'
      }
      if (row.transferStatus == 1) {
        return '车辆调出'
      }
      if (row.transferStatus == 3) {
        return '车辆调拨中'
      }
      if (row.carStatus == 1) {
        return '待整备'
      }
      if (row.carStatus == 2) {
        return '备发车'
      }
      if (row.carStatus == 3) {
        return '预定中'
      }
      if (row.carStatus == 4 || row.carStatus == 6) {
        return '用车中'
      }
      if (row.carStatus == 5) {
        return '同行借出'
      }
    },
  },
}
</script>
<style>
.sucess-text{
  color: #13ce66;font-size: 12px
}
.warning-text{
  color: #ffba00;font-size: 12px
}
.danger-text{
  color: #ff4949
}
</style>
